<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=0">
    <title>樱花跑</title>
    <link  rel="stylesheet" href="{$_C.hy_path}css/info/pubil.css" />
    <link  rel="stylesheet" href="{$_C.hy_path}css/info/index.css" />
	
</head>
<body>
	<div class="yinbox">
		<img src="{$_C.hy_path}images/info/bei_bg.png" />
		<div class="ksmile"><img src="{$_C.hy_path}images/info/ksmile logo.png"/></div>
		<div class="titleda"><img src="{$_C.hy_path}images/info/titleda.png"/></div>
		<div class="titexiao"><img src="{$_C.hy_path}images/info/titexiao.png"/></div>
		<div class="tianx"><img src="{$_C.hy_path}images/info/tianx.png"/></div>
		<div class="dahua"><img src="{$_C.hy_path}images/info/dahua.png"/></div>
		<div class="kuang">
			<input type="text" name="username" id="username" placeholder="请输入你的“姓名”"   value="{$info.username}"/>
			<input type="text" name="phone" id="phone"  placeholder="请输入11位手机号码" value="{$info.phone}" />
		</div>
		<div class="butt" onclick="saveInfo()"  ><img src="{$_C.hy_path}images/info/butt.png"/></div>
        <div class="logohan"><img src="{$_C.hy_path}images/info/logohan.png"/></div>
	</div>
	
<script type="text/javascript" src="{$_C.hy_path}js/jquery-1.10.2.min.js"></script>

<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	
<script>
		   
		 var is_send = false;
		 
		 var status = '{$info.status}';
		 
		  wx.config({
		    debug: false, 
		   appId: '{$jsdk.appId}',
				timestamp: {$jsdk.timestamp},
				nonceStr: '{$jsdk.nonceStr}',
				signature: '{$jsdk.signature}',
		    jsApiList: [
		      // 所有要调用的 API 都要加到这个列表中
			  'onMenuShareTimeline',
	      	  'onMenuShareAppMessage',
		      'addCard',

		    ]
		  });
		
		  
		  wx.ready(function () {
			
			 wx.onMenuShareTimeline({
			    title: '樱花跑',
			     link:'http://g4.shfyuan.com/xy/index.php?g=mobile&m=info&a=record',
			     imgUrl: 'http://g4.shfyuan.com/xy/Mobile/Webroot/gf/images/info/share.png',
			      trigger: function (res) {
			       
			      },
			      success: function (res) {
			    	 
			      },
			      cancel: function (res) {
			       
			      },
			      fail: function (res) {
			        showMsg(JSON.stringify(res));
			      }
		    });
		    
			wx.onMenuShareAppMessage({
			    link:'http://g4.shfyuan.com/xy/index.php?g=mobile&m=info&a=record',
			     title: '樱花跑',
			    desc: '首次召唤广府跑团征战韩国樱花跑－跑在樱花烂漫时',
			  	imgUrl: 'http://g4.shfyuan.com/xy/Mobile/Webroot/gf/images/info/share.png',
			    success: function () { 
			    	
			    },
			    cancel: function () { 
			        // 用户取消分享后执行的回调函数
			    }
		});
			  
		 
		  });
		  
		    function saveInfo(){
		    	
		    	
		    	if(status>0)
	    		{
		    		showMsg("你已经领取过了。");
	    			return;
	    		}
		    	
		    	if(is_send)
	    		{
	    			showMsg("数据提交中。");
	    			return;
	    		}
		    	
		    	
		    	
				var saveUrl = "index.php?g=mobile&m=info&a=saveUser";
				var username = $("#username").val();
				var phone = $("#phone").val();
				if(username==""){
					showMsg("请填写姓名。");
					return false;
				}
				if(phone==""){
					showMsg("请填写电话号码。");
					return false;
				}
				var date = {
						username:username,
						phone:phone
				}
				
				is_send = true;
				
				$.post(saveUrl,date,function(res){
					
					 is_send = false;
					 
					if(res.error==0){
						showMsg("卡券将马上发放。");
						
						setTimeout(function(){
							
							wx.addCard({
					              cardList: res.data,
					              success: function (dat) {
					            	  
					            	  get_card();
					            	  
					              }
					            });
							
						},1000);
						
						 
						 
						  
					}else if(res.error==2){
						showMsg("你已经领取过了。");
					}else{
						showMsg(res.content);
					}
				},"json");
			}
		  

	/* 	  function try_card(id)
		  {
				  
			  var url = "index.php?g=mobile&m=picture&a=ajaxCard";
				
			  var data = { id:id };
			  
				$.post(url,data,function(cardlist){
					
					
					 wx.addCard({
			              cardList: cardlist,
			              success: function (res) {
			            	
			            	  
			            	  
			            	  get_card(res,id);
			            	  
			              }
			            });
					 
					  is_send = false;
				},"json");
          	  
            	
		  } */
		  
		  
		  function get_card()
		  {
				  
			  var url = "index.php?g=mobile&m=info&a=getCard";
				
				$.post(url,"",function(res){
					showMsg("领取成功。");
					//document.getElementById('mcover').style.display='block';
					
				},"text");
          	  
            
		  }
		  
		 
		   function showMsg(msg){
				//is_send = false;
				showToast(msg);
			 }
		   
			  
			
		
		function mysa(){
			$(".yinbox .titexiao").addClass('myasd')
		}
		setInterval(mysa,300);
		
		

		var Toast = function(config){  
		    this.context = config.context==null?$('body'):config.context;//上下文  
		    this.message = config.message;//显示内容  
		    this.time = config.time==null?3000:config.time;//持续时间  
		    this.left = config.left;//距容器左边的距离  
		    this.top = config.top;//距容器上方的距离  
		    this.init();  
		}  
		
		var msgEntity;  
		Toast.prototype = {  
		    //初始化显示的位置内容等  
		    init : function(){  
		        $("#toastMessage").remove();  
		        //设置消息体  
		        var msgDIV = new Array();  
		        msgDIV.push('<div id="toastMessage">');  
		        msgDIV.push('<span>'+this.message+'</span>');  
		        msgDIV.push('</div>');  
		        msgEntity = $(msgDIV.join('')).appendTo(this.context);  
		        //设置消息样式  
		        var left = this.left == null ? '50%': this.left;  
		        var top = this.top == null ? '40%' : this.top; 
		        var margin_left = (msgEntity.find('span').width()/2);
		        //alert(margin_left);
		        msgEntity.css({ position:'fixed',top:top,'z-index':'99',left:left,'background-color':'gray',color:'white','font-size':'14px',padding:'10px','margin-left':-margin_left });  
		        msgEntity.hide();
		        
		    },  
		    //显示动画  
		    show :function(){  
		        msgEntity.fadeIn(1000);
		        setTimeout("msgEntity.fadeOut(1000)",this.time);
		        
		    }  
		          
		}  
		
		//显示toast
		function showToast(msg)
		{
			//alert(1);
			new Toast({ message:msg }).show();
		}
		
		//隐藏toast
		function hideToast()
		{
			msgEntity.fadeOut(1000);
		}
		
	</script>
</body>
</html>